
 /*
author:
time : 2021年10月26日
 */ 
<template>
  <div>
    <!-- 搜索框 -->
    <div style="margin: 30px 0 0 70px">
      <el-input placeholder="请输入内容" v-model="input" class="input">
        <el-button
          class="btn"
          slot="append"
          icon="el-icon-search"
          @click="search"
        ></el-button>
      </el-input>
      <!-- <Ssearch @dateLest="dateLest"/> -->
      <button class="add" type="buttom" @click="add()">
        <i class="icon el-icon-plus"></i> 增加产品
      </button>
    </div>
    <!-- 表格 -->
    <div class="content_table">
      <el-table :data="adminList" style="width: 99%">
        <el-table-column label="ID" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="手机名称" width="140">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="手机类型" width="140">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.phone_type }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="手机尺寸" width="140">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <!-- <el-tag size="medium">{{ scope.row.password }}</el-tag> -->
              <span>{{ scope.row.phone_size }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="运行内存" width="140">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <!-- <el-tag size="medium">{{ scope.row.password }}</el-tag> -->
              <span>{{ scope.row.electric }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="手机内存" width="150">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.thickness }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="图片">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <img :src="`${imageName}${scope.row.picture}`" alt="" />
            </div>
          </template>
        </el-table-column>
        <el-table-column label="价格" width="130">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.price }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="手机品牌" width="130">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.pingpai }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="edit(scope.row)">编辑</el-button>
            <!-- <el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button> -->
            <el-popconfirm
              confirm-button-text="确定"
              cancel-button-text="取消"
              icon="el-icon-info"
              icon-color="red"
              title="确定删除这一条数据吗？"
              @onConfirm="del(scope.row.id)"
            >
              <el-button slot="reference" size="mini" type="danger"
                >删除</el-button
              >
            </el-popconfirm>
            <el-button size="mini" @click="xq(scope.row)" type="info"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="page"
        :page-size="pageSize"
        layout="total, prev, pager, next,jumper"
        :total="count"
      >
      </el-pagination>
    </div>
    <!-- 模态框 -->
    <el-dialog title="产品详情" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <!-- <el-form-item label="手机名称" :label-width="formLabelWidth">
          <el-input v-model="form.name"  autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="产品参数" :label-width="formLabelWidth">
          <el-input v-model="form.parameter" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="影像系统" :label-width="formLabelWidth">
          <el-input v-model="form.yingxiang" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="续航充电" :label-width="formLabelWidth">
          <el-input v-model="form.Endurance" autocomplete="off"></el-input>
        </el-form-item> -->
        <p>手机名称:{{form.name}}</p>
        <p>手机类型:{{form.phone_type}}</p>
        <p>手机尺寸:{{form.phone_size}}</p>
        <p>运行内存:{{form.electric}}</p>
        <p>手机内存:{{form.thickness}}</p>
        <p>价    格:{{form.price}}</p>
        <p>手机品牌:{{form.pingpai}}</p>
        <p>产品参数:{{form.parameter}}</p>
        <p>图片:</p>
     <img v-for="item in form.pictures" :key="item" :src="`${imageName}${item}`"/>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close()">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import Ssearch from '../../layout/Ssearch.vue'
import { getProduce, deleteProduce, postupLoad } from "@/api/table";
export default {
  data() {
    return {
      input: "",
      value: "100",
      // 是否启用,默认启用
      value1: true,
      adminList: [],
      //查询关键字
      keyName: "",
      // 数据库总页数
      count: 0,
      // 当前页数
      page: 1,
      // 每页显示几条数据
      pageSize: 7,
      tp:'',
      // 模态框默认关闭
      dialogFormVisible: false,
      form: {
        id: null,
        name: "",
        phone_type: "",
        phone_size: "",
        electric: "",
        thickness: "",
        picture: "",
        price: "",
        pingpai: "",
        parameter: "",
        yingxiang: "",
        Endurance: "",
      },
      // 模态框输入长度
      formLabelWidth: "120px",

      imageUrl: "",
      imageName: "http://192.168.3.180:7001/",
    };
  },

  created() {
    this.getDate();
   
  },

  methods: {
    handleCurrentChange() {
      this.getDate();
    },
    // 获取产品数据的方法
    getDate() {
      const params = {
        page: this.page,
        number: this.pageSize,
        name: this.keyName,
      };
      console.log(params);
      getProduce(params).then((res) => {
        console.log(res);
        if (res.code === 0) {
          // this.adminList = res.data;
          this.adminList = [...res.data];
          this.count = res.count;
        }
        if (res.code === 4004) {
          this.adminList = res.data;
          this.count = res.count;
          this.page = res.page;
        }
      });
    },
    // 上传图片/编辑图片
    addImg(event) {
      const i = event.target.files[0];
      const formdata = new FormData();
      formdata.append("one", i);
      postupLoad(formdata).then((res) => {
        console.log(res.data);
        if (res.code === 0) {
          this.form.picture = res.data;
          console.log(this.form.picture);
        }
      });
    },
    // 根据关键字查询
    search() {
      this.keyName = this.input;
      this.getDate();
    },
    xq(data) {
      // 显示模态框
      this.dialogFormVisible = true;
      this.form.name = data.name;
      this.form.phone_type = data.phone_type;
      this.form.phone_size = data.phone_size;
      this.form.electric = data.electric;
      this.form.thickness = data.thickness;
      this.form.picture = data.picture;
      this.form.price = data.price;
      this.form.pingpai = data.pingpai;
      this.form.parameter = data.parameter;
      this.form.yingxiang = data.yingxiang;
      this.form.Endurance = data.Endurance;
    },
    close() {
      this.dialogFormVisible = false;
    },
    // 新增产品
    add() {
      // this.isEdit = true;
      this.$router.push({ path: "/product_add/product_add" });
    },
    // 编辑产品
    edit(data) {
      // 显示模态框
      // this.dialogFormVisible = true;
      this.isEdit = false;
      this.form.id = data.id;
      this.form.name = data.name;
      this.form.phone_type = data.phone_type;
      this.form.phone_size = data.phone_size;
      this.form.electric = data.electric;
      this.form.thickness = data.thickness;
      this.form.picture = data.picture;
      this.form.price = data.price;
      this.form.pingpai = data.pingpai;
      this.form.parameter = data.parameter;
      this.form.yingxiang = data.yingxiang;
      this.form.Endurance = data.Endurance;
      console.log(this.form);
      // this.$emit('form',this.form)
      this.$router.push({ path: "/product_/product_edit", query: this.form });
    },
    // 删除产品
    del(id) {
      // this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(() => {
      deleteProduce(id).then((res) => {
        if (res.code === 0) {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // 删除后重新渲染
          this.getDate();
        }
      });
      // })
      // .catch(() => {
      //   this.$message({
      //     type: "info",
      //     message: "已取消删除",
      //   });
      // });
    },
    pageChange(page) {
      console.log(page);
      this.page = page;
      this.getDate();
    },
  },
};
</script>

<style lang="scss" scoped>
.fa {
  margin-right: 5px;
}

.bread {
  width: 100%;
  height: 30px;
  padding: 10px 0;
  display: flex;
  padding-left: 10px;
  align-items: center;
  .el-breadcrumb {
    line-height: 30px;
    width: 100%;
    background-color: #fff;
  }
}
.input {
  background-color: #fff;
  width: 300px;

  margin: 0px 0px 20px 10px;
}
.add {
  background-color: rgb(133, 190, 228);
  color: white;
  border: none;
  line-height: 38px;
  border-radius: 5px;
  margin-left: 10px;
}
.el-dialog {
  width: 600px;
}
.content_table {
  width: 90%;

  margin: 0 auto;
}

img {
  width: 70px;
  height: 60px;
}
.block {
  margin: 20px 80px;
  display: inline-block;
}
.el-button {
  margin-right: 10px;
}
</style> 